package com.fenghuajueli.module_home.recycler

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

/**
 * =====================================================
 * 作    者: Xiuz
 * 创建日期: 2020/10/10 11:11
 * 描    述:
 * =====================================================
 */
class GridItemDecoration(private val int1: Int, private val spanCount: Int) : RecyclerView.ItemDecoration() {
    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {

        val index = parent.getChildAdapterPosition(view)
        when (index % spanCount) {
            0 -> {
                outRect.run {
                    left = int1
                    top = 0
                    right = int1 / 2
                    bottom = int1
                }
            }

            spanCount - 1 -> {
                outRect.run {
                    left = int1 / 2
                    top = 0
                    right = int1
                    bottom = int1
                }
            }

            else -> {
                outRect.run {
                    left = int1 / 2
                    top = 0
                    right = int1 / 2
                    bottom = int1
                }
            }
        }
    }
}